﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.IdentityModel.Tokens;

namespace ZeroSum.Plugin.Authentication.JwtBearer.Authentication;

/// <summary>
///     定义JwtBearer服务，负责JwtToken的创建，验证，刷新等业务
/// </summary>
public interface IJwtBearerService
{
    public string? CreateToken(IDictionary<string, object>? payload, long? accessExpireTime = null);

    /// <summary>
    ///     生成刷新 Token
    /// </summary>
    /// <param name="accessToken"></param>
    /// <returns></returns>
    public string? GenerateRefreshToken(string? accessToken);

    /// <summary>
    ///     自动刷新 Token 信息
    /// </summary>
    /// <param name="context"></param>
    /// <param name="httpContext"></param>
    /// <param name="tokenPrefix"></param>
    /// <returns></returns>
    public bool AutoRefreshToken(AuthorizationHandlerContext context, DefaultHttpContext? httpContext,
        string tokenPrefix = "Bearer ");

    /// <summary>
    ///     生成Token验证参数
    /// </summary>
    /// <returns></returns>
    public TokenValidationParameters CreateTokenValidationParameters();
}